<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
  <script>

    // 练习二: 传入宽高, 返回面积
    function getRectangleArea(width, height) {
      // var area = width * height
      // return area
      return width * height
    }

    var area1 = getRectangleArea(20, 30)
    var area2 = getRectangleArea(50, 66)
    console.log("area1:", area1)
    console.log("area2:", area2)


    // 练习三: 传入半径radius, 计算圆形的面积
    function getCircleArea(radius) {
      return Math.PI * radius * radius
    }
    var area3 = getCircleArea(10)
    var area4 = getCircleArea(25)
    console.log("area3:", area3)
    console.log("area4:", area4)

    // 练习四: 传入一个数字n, 计算1~n的数字和
    function sumN(n) {
      // 1.加对n的判断
      if (n <= 0) {
        console.log(`您传入的${n}是有问题的`)
        return
      }

      // 2.真正对1~n的数字进行计算
      // 1~n的数字和
      // 1~5 1 2 3 4 5
      var total = 0
      for (var i = 1; i <= n; i++) {
        total += i
      }
      return total
    }

    var result1 = sumN(5)
    var result2 = sumN(10)
    console.log(`result1: ${result1}, result2: ${result2}`)

    var result3 = sumN(-10)
    console.log("result3:", result3)

  </script>

</body>
</html>